package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.kcwl.carrier.domain.entity.CarrierCompanyInfo;
import com.kcwl.carrier.domain.repository.ICarrierCompanyInfoRepository;
import com.kcwl.carrier.infrastructure.repository.mapper.CarrierCompanyInfoMapper;
import com.kcwl.carrier.infrastructure.repository.po.CarrierCompanyInfoPO;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import com.kcwl.framework.utils.KcBeanConverter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 刘旭超
 * @date 2022年07月11日 16:33
 * @Description
 */
@Service
public class CarrierCompanyInfoRepositoryImpl extends BaseRepositoryImpl<CarrierCompanyInfoMapper, CarrierCompanyInfoPO> implements ICarrierCompanyInfoRepository {

    @Resource
    private CarrierCompanyInfoMapper carrierCompanyInfoMapper;

    @Override
    public CarrierCompanyInfo queryByCarrierId(Long carrierId) {
        QueryWrapper<CarrierCompanyInfoPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("carrier_id", carrierId);
        return KcBeanConverter.toBean(carrierCompanyInfoMapper.selectOne(queryWrapper), CarrierCompanyInfo.class);
    }

    @Override
    public int insert(CarrierCompanyInfo carrierCompanyInfo) {
        carrierCompanyInfo.setCreateTime(new Date());
        carrierCompanyInfo.setCreateUserId(carrierCompanyInfo.getCreateUserId());
        return carrierCompanyInfoMapper.insert((KcBeanConverter.toBean(carrierCompanyInfo, CarrierCompanyInfoPO.class)));
    }

    @Override
    public int updateByCarrierId(CarrierCompanyInfo carrierCompanyInfo) {
        UpdateWrapper<CarrierCompanyInfoPO> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("carrier_id", carrierCompanyInfo.getCarrierId());
        carrierCompanyInfo.setUpdateTime(new Date());
        return carrierCompanyInfoMapper.update(KcBeanConverter.toBean(carrierCompanyInfo, CarrierCompanyInfoPO.class), updateWrapper);
    }

    @Override
    public Class<CarrierCompanyInfoPO> getPoClass() {
        return CarrierCompanyInfoPO.class;
    }
}
